package com.zenithmind.disk.service.impl;

import com.zenithmind.disk.pojo.domain.Files;
import com.zenithmind.disk.pojo.dto.FileDTO;
import com.zenithmind.disk.pojo.query.FileQuery;
import com.zenithmind.disk.pojo.vo.FileVO;
import com.zenithmind.disk.service.*;
import com.zenithmind.common.result.PageResult;
import jakarta.servlet.http.HttpServletResponse;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.List;

/**
 * 文件操作组合服务实现
 * 遵循依赖倒置原则：依赖抽象接口而非具体实现
 * 遵循单一职责原则：专注于协调各个专门的服务
 * 遵循组合优于继承原则：通过组合多个服务来提供完整功能
 */
@Slf4j
@Service
@RequiredArgsConstructor
public class FileOperationServiceImpl implements FileOperationService {

    private final FilesService filesService;
    private final FileDownloadService fileDownloadService;
    private final FileManagementService fileManagementService;

    // 基本文件操作 - 委托给FilesService
    @Override
    public FileVO uploadFile(MultipartFile file, String userId, String parentId) {
        return filesService.uploadFile(file, userId, parentId);
    }

    @Override
    public FileVO createFolder(FileDTO fileDTO) {
        return filesService.createFolder(fileDTO);
    }

    @Override
    public List<FileVO> listFiles(String userId, String parentId) {
        return filesService.listFiles(userId, parentId);
    }

    @Override
    public FileVO renameFile(FileDTO fileDTO) {
        return filesService.renameFile(fileDTO);
    }

    @Override
    public boolean moveFile(String fileId, String targetId, String userId) {
        return filesService.moveFile(fileId, targetId, userId);
    }

    // 文件管理操作 - 委托给FileManagementService
    @Override
    public boolean deleteFile(String fileId, String userId) {
        return fileManagementService.deleteFile(fileId, userId);
    }

    @Override
    public FileVO getFileInfo(String fileId) {
        return fileManagementService.getFileInfo(fileId);
    }

    @Override
    public PageResult<FileVO> filePage(FileQuery fileQuery) {
        return fileManagementService.filePage(fileQuery);
    }

    @Override
    public boolean deleteBatchFiles(List<String> ids) {
        return fileManagementService.deleteBatchFiles(ids);
    }

    @Override
    public FileVO addOrUpdateFileByAdmin(Files file) {
        return fileManagementService.addOrUpdateFileByAdmin(file);
    }

    // 文件下载操作 - 委托给FileDownloadService
    @Override
    public void downloadFile(String fileId, String userId, HttpServletResponse response) throws IOException {
        fileDownloadService.downloadFile(fileId, userId, response);
    }

    @Override
    public void downloadDirectory(String folderId, HttpServletResponse response) throws IOException {
        fileDownloadService.downloadDirectory(folderId, response);
    }

    @Override
    public String getFilePath(String fileId, String userId) {
        return fileDownloadService.getFilePath(fileId, userId);
    }
}
